package com.example.sxy_project;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

public class WeixinFragment extends Fragment {
    private List<Weixin> weiList = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.weixin_fragment,container,false);
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        inints();

        WeixinAdapter adapter = new WeixinAdapter(this.getContext(),R.layout.weixin_content_item,
                weiList);
        ListView listView = getView().findViewById(R.id.weixin_listview);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Weixin weixin = weiList.get(position);
                if (weixin.getName()=="宋欣益"){
                    Intent intent = new Intent(getActivity(), ChatActivity.class);
                    startActivity(intent);
                }else {
                    Toast.makeText(getActivity(),"不是通讯录里的联系人( ´_ゝ`)", Toast.LENGTH_SHORT).show();
                }
            }
        });


    }

    private void inints() {
        for (int i=0; i<2;i++){
            Weixin w1 = new Weixin();
            w1.setImageId(R.drawable.dyhxx);
            w1.setName("订阅号服务");
            w1.setNeirong("近日，多地区狂风来袭，多加注意..");
            weiList.add(w1);

            Weixin w2 = new Weixin();
            w2.setImageId(R.drawable.wx);
            w2.setName("运动健康");
            w2.setNeirong("[应用消息]");
            weiList.add(w2);

            Weixin w3 = new Weixin();
            w3.setImageId(R.drawable.wx);
            w3.setName("微信支付");
            w3.setNeirong("微信支付凭证");
            weiList.add(w3);

            Weixin w4 = new Weixin();
            w4.setImageId(R.drawable.tongzhi);
            w4.setName("微信记账本");
            w4.setNeirong("昨日记账日报，点击查看详情");
            weiList.add(w4);

            Weixin w5 = new Weixin();
            w5.setImageId(R.drawable.qq);
            w5.setName("QQ邮箱提醒");
            w5.setNeirong("Nintendo (Hongkong) Limited:最后召集！ ...");
            weiList.add(w5);

            Weixin w6 = new Weixin();
            w6.setImageId(R.drawable.img2);
            w6.setName("宋欣益");
            w6.setNeirong("好久不见!");
            weiList.add(w6);
        }

    }
}

